package com.example.server.controller.admin;

import com.example.server.common.config.annotation.MustLogin;
import com.example.server.common.config.auth.TokenUser;
import com.example.server.common.constant.Result;
import com.example.server.service.admin.ArticleService;
import com.example.server.vo.ArticleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;


@Api(tags = "Admin文章相关接口")
@RestController
@RequestMapping("/admin/article")
public class AdminArticleController {
    @Resource
    ArticleService articleService;

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "修改文章", notes = "修改文章")
    @PostMapping("/update")
    public Result updateArticleById(@RequestBody ArticleVO articleVO, @ApiIgnore TokenUser tokenUser) {
        return articleService.updateArticleById(articleVO, tokenUser.getCustomerId());
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "新增帮助文档", notes = "新增帮助文档")
    @PostMapping("/add/help")
    public Result addArticleByHelp(@RequestBody ArticleVO articleVO, @ApiIgnore TokenUser tokenUser) {
        return articleService.addArticleByHelp(articleVO, tokenUser.getCustomerId());
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "系统文档列表", notes = "系统文档列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "page", required = true),
            @ApiImplicitParam(value = "数量", name = "limit", required = true),
            @ApiImplicitParam(value = "关键字", name = "key", required = false)
    })
    @GetMapping("/list/sys")
    public Result sysArticleList(Integer page, Integer limit, String key) {
        return articleService.sysArticleList(page, limit, key);
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "帮助文档列表", notes = "帮助文档列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "current", required = true),
            @ApiImplicitParam(value = "数量", name = "size", required = true),
            @ApiImplicitParam(value = "关键字", name = "key", required = false)
    })
    @GetMapping("/list/help")
    public Result helpArticleList(Integer current, Integer size, String key) {
        return articleService.helpArticleList(current, size, key, null);
    }

    @MustLogin(isAdmin = true)
    @ApiOperation(value = "修改帮助文档状态", notes = "修改帮助文档状态")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "文章id", name = "articleId", required = true),
            @ApiImplicitParam(value = "文章状态", name = "enable", required = true)
    })
    @PostMapping("/update/help/status")
    public Result updateArticleStatusByHelp(Integer articleId, Integer enable, @ApiIgnore TokenUser tokenUser) {
        return articleService.updateArticleStatusByHelp(articleId, enable, tokenUser.getCustomerId());
    }
}
